package interceptcrossing.ui.command;

import interceptcrossing.Intercept;
import interceptcrossing.command.Command;
import interceptcrossing.ui.MainWindowDirector;

import java.util.Collection;
import java.util.HashSet;

public class ImportInterceptsCommand implements Command {

	private MainWindowDirector windowDirector;
	private Collection<Intercept> intercepts;

	public ImportInterceptsCommand(MainWindowDirector windowDirector, Collection<Intercept> intercepts) {
		if (windowDirector == null) {
			throw new NullPointerException("Main window director cannot be null");
		}

		this.windowDirector = windowDirector;
		this.intercepts = new HashSet<Intercept>();
		this.intercepts.addAll(intercepts);
	}

	public void doCommand() {
		this.windowDirector.interceptsGenerated(this.intercepts);
	}

	public String getDescription() {
		return "Импорт отрезков";
	}

	public void undoCommand() {
		for (Intercept intercept : this.intercepts) {
			this.windowDirector.removeIntercept(intercept);
		}
	}
}